//头像 用户昵称显示
function getUserInfo() {
  axios.get('/my/user/userinfo').then(res => {
    //解构赋值
    let {nickname , user_pic , username } = res.data.data
    //昵称判断
    let name = nickname || username
    $('.username').text(name)
    if (user_pic) {
      //有头像
      $('.layui-nav-img').attr('src', user_pic).show()
    } else {
      //没有头像
      let first = name.substring(0, 1).toUpperCase()
      $('.user-avatar').text(first).css('display', 'inline-block')
    }
  })
}
getUserInfo()

//退出登录
$('#logout').on('click', function () {
  //是否弹出
  layer.confirm('确定退出吗?', {icon: 3,title: '提示'}, function (index) {
    //退出登录删除token
    localStorage.removeItem('token')
    //退出登录之后跳转到登录
    location.href = './login.html'
    layer.close(index); //关闭弹出层
  });
})
